package com.zhida.jiyangcenter.membership

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import chooongg.base.annotation.ContentLayout
import chooongg.base.annotation.TitleBar
import com.zhida.jiyangcenter.R
import com.zhida.jiyangcenter.mian.BaseActivity
import com.zhida.jiyangcenter.mian.BaseFragment
import com.zhida.jiyangcenter.utils.SP
import com.zhida.jiyangcenter.utils.glideImage

import kotlinx.android.synthetic.main.activity_buy_member.*

@TitleBar(false)
@ContentLayout(R.layout.activity_buy_member)
class MembershipBuyActivity:BaseActivity() {
    private lateinit var adapter: Adapter
    private val fragments = ArrayList<BaseFragment>()
    override fun initConfig(savedInstanceState: Bundle?) {
        title_bar.title("会员中心").navigationIcon(R.drawable.iv_back_fill) {
            finish()
        }
        fragments.add(BuyMemberFragment())
        fragments.add(RechargeFragmnet())
        adapter = Adapter(
            supportFragmentManager,
            fragments
        )
        view_page_member.setNoScroll(true)
        view_page_member.adapter = adapter
        view_page_member.offscreenPageLimit = fragments.size - 1
        tv_name.text= SP.nickname.get()?:SP.account.get().toString()
        glideImage(niv_head,SP.avatar_path.get())
        ll_buy_member.setOnClickListener {
            ll_buy_member.setBackgroundResource(R.drawable.bg_fill_99ebcf_top8)
            ll_pay.setBackgroundResource(R.drawable.bg_fill_f9f9f9_top8)
            view_page_member.setCurrentItem(0,true)
        }
        ll_pay.setOnClickListener {
            ll_pay.setBackgroundResource(R.drawable.bg_fill_99ebcf_top8)
            ll_buy_member.setBackgroundResource(R.drawable.bg_fill_f9f9f9_top8)
            view_page_member.setCurrentItem(1,true)
        }
    }
    private class Adapter(fm: FragmentManager, val fragments: ArrayList<BaseFragment>) :
        FragmentPagerAdapter(fm) {
        override fun getItem(position: Int) = fragments[position]
        override fun getCount() = fragments.size
        override fun getPageTitle(position: Int) = fragments[position].getTitle()
    }
}